package com.oly.cms.general.service.search;

import java.util.List;

import com.oly.cms.common.model.properties.OlyWebConfigProetries;
import com.oly.cms.general.mapper.WebSearchMapper;
import com.oly.cms.general.model.po.WebTag;
import com.oly.cms.general.service.IWebSearchService;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.config.service.ISysConfigService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WebTagServiceImpl implements IWebSearchService {

    @Autowired
    private WebSearchMapper webSearchMapper;

    @Autowired
    private ISysConfigService configService;

    public List<WebTag> listWebTags(WebTag webTag) {
        return webSearchMapper.listWebTags(webTag);
    }

    public WebTag getWebTagByTagId(long tagId) {
        return webSearchMapper.getWebTagByTagId(tagId);
    }

    public List<WebTag> getWebTagByVisibleAndType(Integer tagType, Integer visible, String themeName) {
        WebTag webTag = new WebTag();
        webTag.setTagType(tagType);
        webTag.setVisible(visible);
        setSupportType(webTag, themeName);
        return this.listWebTags(webTag);
    }

    private void setSupportType(WebTag webTag, String themeName) {
        String supportType = configService.selectConfigDefauleValue(themeName, OlyWebConfigProetries.ARTICLE_TYPES);
        if (StringUtils.isNotEmpty(supportType)) {
            webTag.getParams().put("supportType", supportType);
        }

    }
}
